package com.jfinal.bbsapp.common.kit;

import java.util.Random;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.jfinal.kit.PropKit;

public class SendSmsal {
	 //产品名称:云通信短信API产品,开发者无需替换
    static final String product = "Dysmsapi";
    //产品域名,开发者无需替换
    static final String domain = "dysmsapi.aliyuncs.com";
    private String accessKeyId = PropKit.get("SecretId");
	private String accessKeySecret = PropKit.get("SecretKey");
	private String SignName = PropKit.get("SignName");
	private String SMS_NO = PropKit.get("SMS_NO");
    
	public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("ap-northeast-1", "LTAI5tAsBh5Tp6DMM5pxaU7E", "LXHvjGIWWx7KJP9QcCE28QSo0Dzk6Q");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", "13676960086");
        request.putQueryParameter("SignName", "河南步步升文化科技");
        request.putQueryParameter("TemplateCode", "SMS_292780028");
        request.putQueryParameter("TemplateParam", "{\"code\":\"1111\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
	
	public String sendSms(String mobile, String content,String checkminute) {
		DefaultProfile profile = DefaultProfile.getProfile("ap-northeast-1", accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain(domain);
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("SignName", SignName);
        request.putQueryParameter("TemplateCode", SMS_NO);
        request.putQueryParameter("TemplateParam", "{\"code\":\""+ content +"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
		return null;
	}
	
	public int randomInt() {
		Random ne = new Random();
		int x = ne.nextInt(9000) + 1000;
		return x;
	}
}
